let recommen = document.getElementById('recommen')

let btn = document.getElementById('btn')

// 商品详情页界面 4.3、国内折扣商品详情页功能界面

var num = location.href.split("=")[1] //对接收的上个页面的值进行切割
// console.log(location.href.split("=")[0]);

fn(num)
function fn(num = 0) {
    ajax({
        url: "http://chst.vip:1234/api/getdiscountproduct?productid=" + num + " ",
        
        success(res) {
            res.result.forEach(item => {
                let div = document.createElement('a')//内容区域最外层盒子
                // div.href=
                div.id = "shop"
                let img = document.createElement("a")//图片放置
                img.innerHTML = item.productImg
                img.id="shop-img"
                // img.href=item.productInfo1//评论的超链接
                let intro = document.createElement("div") //下方放置产品信息的盒子
                intro.innerHTML = item.productName
                intro.id = "intro"
                let price = document.createElement("p")  //放置价格
                price.innerHTML = item.productPrice
                price.id = "price"
                let p = document.createElement("p")
                p.id = "shop-p"
                p.innerHTML = item.productInfo
                let source = document.createElement('div') //放置最下面的来源事件等信息
                source.id = "source"
                source.innerHTML = `${item.productFrom} | ${item.productTime}  ${item.productTips}`
                div.appendChild(intro)
                div.appendChild(price)
                div.appendChild(source)
                div.appendChild(p)
                div.appendChild(img)

                recommen.appendChild(div)
               
                num1 = item.productComment
                
               
                ffn(num,num1)
                
            });
        }



    })

function ffn(num,num1){


    ajax({

        url: "http://chst.vip:1234/api/getmoneyctrl?productid=" + num + " ",

        success(res) {
            console.log("城市" + num);
            var arr = res.result[0].productCity
            console.log(res.result[0]);
            let ul = document.createElement('div')
            ul.innerHTML = arr
            let btn = document.createElement("a")
            btn.href = "moneyctrl.html"   //点击跳转
            btn.innerText = "前往购买"
            btn.id = "shop-btn"
            recommen.appendChild(ul)
            recommen.appendChild(btn)
            let img1 =document.getElementById("img11")
            console.log(img1);
            recommen.appendChild(img1)
            let discuss = document.createElement("div")  //评论
            discuss.innerHTML = num1
            console.log(num1);
            recommen.appendChild(discuss)
        }
    })

}
}


// document.querySelector('#recommen').onscroll = function () {
//     btn.onclick = function () {
//         document.querySelector('#recommen').scrollTop = 0
//     }
// }

// let btn=document.getElementById("btn")
document.querySelector('#recommen').onscroll = function() {
    btn.onclick = function() {

        //加入动画过度效果
    //         document.querySelector('#recommen').scrollTop = 0
    // let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        let timer = setInterval(() => {
           document.querySelector('#recommen').scrollTop -=20
            if (document.querySelector('#recommen').scrollTop <= 0) {
                clearInterval(timer)
            }
        },10)
   
          
        }
    }
